package com.zjsd.sqeybusiness.controller;

import java.text.ParseException;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.framework.web.domain.server.Sys;
import com.zjsd.sqeybusiness.domain.Achievements;
import com.zjsd.sqeybusiness.domain.PlatformProductCategory;
import com.zjsd.sqeybusiness.dto.*;
import com.zjsd.sqeybusiness.service.IAchievementsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务员业绩
Controller
 *
 * @author Zheng
 * @date 2021-07-14
 */
@RestController
@RequestMapping("/sqeybusiness/achievements")
public class AchievementsController extends BaseController
{
    @Autowired
    private IAchievementsService achievementsService;


    /**
     * 查询业务员业绩列表 @PreAuthorize("@ss.hasPermi('sqeybusiness:achievements:list')")
     */

    @GetMapping("/list")
    public TableDataInfo list(Achievements achievements)
    {
        startPage();
        List<Achievements> list = achievementsService.selectAchievementsList(achievements);
        return getDataTable(list);
    }

    @GetMapping("/listAchDetail")
    public TableDataInfo listAchDetail(Achievements achievements) throws ParseException {
        startPage();
        List<Achievements> list = achievementsService.listAchDetail(achievements);
        return getDataTable(list);
    }

    @GetMapping("/examAchieList")
    public TableDataInfo examAchieList(Achievements achievements) throws ParseException {
        startPage();
        List<Achievements> list = achievementsService.examAchieList(achievements);
        return getDataTable(list);
    }

    @GetMapping("/examAchieListDai")
    public AjaxResult examAchieListDai(Achievements achievements) throws ParseException {
        int i  = achievementsService.examAchieListDai(achievements);
        return AjaxResult.success(i);
    }


    /**
     * 导出业务员业绩 @PreAuthorize("@ss.hasPermi('sqeybusiness:achievements:export')")
列表
     */

    //@Log(title = "业务员业绩 ", businessType = BusinessType.EXPORT)
    @GetMapping("/exportEmp")
    public AjaxResult exportEmp(Achievements achievements)
    {
        List<Achievements> list = achievementsService.selectAchievementsList(achievements);
        ExcelUtil<Achievements> util = new ExcelUtil<Achievements>(Achievements.class);
        return util.exportExcel(list, "achievements");
    }

    /**
     * 获取业务员业绩详细信息 @PreAuthorize("@ss.hasPermi('sqeybusiness:achievements:query')")
     */

    @GetMapping(value = "/{achid}")
    public AjaxResult getInfo(@PathVariable("achid") Long achid)
    {
        return AjaxResult.success(achievementsService.selectAchievementsById(achid));
    }

    /**
     * 新增业务员业绩
    @PreAuthorize("@ss.hasPermi('sqeybusiness:achievements:add')")
     */
    //@Log(title = "业务员业绩 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(Achievements achievements)
    {
        System.out.println("开通时间" +achievements.getKtdate());
        return toAjax(achievementsService.insertAchievements(achievements));
    }

    /**
     * 修改业务员业绩  @PreAuthorize("@ss.hasPermi('sqeybusiness:achievements:edit')")

     */

    //@Log(title = "业务员业绩 ", businessType = BusinessType.UPDATE)
    @PostMapping("/updateAchievements")
    public AjaxResult edit( Achievements achievements)
    {
        System.out.println("开通时间" +achievements.getKtdate());
        int i = achievementsService.updateAchievements(achievements);
        return AjaxResult.success(i);
    }



    //@Log(title = "业务员业绩 ", businessType = BusinessType.UPDATE)
    @PostMapping("/queryBakcAchive")
    public AjaxResult queryBakcAchive( Achievements achievements)
    {
        int i = achievementsService.queryBakcAchive(achievements);
        return AjaxResult.success(i);
    }


    /**
     * 开端口审核
     * @param achievements
     * @return
     */
    //@Log(title = "业务员业绩 ", businessType = BusinessType.UPDATE)
    @PostMapping("/examAchievements")
    public AjaxResult examAchievements( Achievements achievements)
    {
        // System.out.println("开通时间" +achievements.getKtdate());
        int i = achievementsService.examAchievements(achievements);
        return AjaxResult.success(i);
    }



    //@Log(title = "业务员业绩 ", businessType = BusinessType.UPDATE)
    @PostMapping("/updateAchievementsWeb")
    public AjaxResult updateAchievementsWeb( Achievements achievements)
    {
        System.out.println("开通时间" +achievements.getKtdate());
        return toAjax(achievementsService.updateAchievements(achievements));
    }

    //@Log(title = "业务员业绩 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult updateAchievements( @RequestBody  Achievements achievements)
    {
        System.out.println("开通时间" +achievements.getKtdate());
        return toAjax(achievementsService.updateAchievementsWeb(achievements));
    }

    /**
     * 删除业务员业绩   @PreAuthorize("@ss.hasPermi('sqeybusiness:achievements:remove')")

     */

    //@Log(title = "业务员业绩 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{achids}")
    public AjaxResult remove(@PathVariable Long[] achids)
    {
        return toAjax(achievementsService.deleteAchievementsByIds(achids));
    }

    /**
     * 查询业务员业绩列表
     */
    @GetMapping("/getProvinceList")
    public TableDataInfo getProvinceList( )
    {
        List<SysDept> list = achievementsService.getProvinceList();
        return getDataTable(list);
    }


    @GetMapping("/queryAchlistByShphone")
    public TableDataInfo queryAchlistByShphone(Achievements achievements )
    {
        List<Achievements> list = achievementsService.queryAchlistByShphone(achievements);
        return getDataTable(list);
    }

    //@Log(title = "查询业务员本月业绩提成情况", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryYwyDeductInfo")
    public AjaxResult queryYwyDeductInfo (ComputeDeductDTO computeDeductDTO) throws ParseException {
        MonthDeductDTO monthDeductDTO = achievementsService.queryYwyDeductInfo(computeDeductDTO);
        return AjaxResult.success(monthDeductDTO);
    }

    //@Log(title = "后台财务查询业务员销售情况", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryEmployeeDeduct")
    public TableDataInfo queryEmployeeDeduct( QueryDTO queryDTO)
    {
        startPage();
        List<EmployeeDeductDTO> list = achievementsService.queryEmployeeDeductNew(queryDTO);
        return getDataTable(list);
    }




    //@Log(title = "导出业务员绩效数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(QueryDTO queryDTO)
    {
        List<EmployeeDeductDTO> list = achievementsService.queryEmployeeDeductNew(queryDTO);
        ExcelUtil<EmployeeDeductDTO> util = new ExcelUtil<EmployeeDeductDTO>(EmployeeDeductDTO.class);
        return util.exportExcel(list, "业务员业绩数据");
    }


    @PostMapping("/updateGsywy")
    public AjaxResult updateGsywy(@RequestBody GsywyDTO gsywyDTO)
    {
        int i = achievementsService.updateGsywy(gsywyDTO);
        return toAjax(i);

    }

    /**
     * 查询平台产品分类列表    @PreAuthorize("@ss.hasPermi('jph:platformProductCategory:list')")
     */

    @PostMapping("/queryDeptments")
    public TableDataInfo list(SysDept sysDept)
    {
        List<SysDept> list = achievementsService.queryDeptments(sysDept);

        return getDataTable(list);
    }


    @PostMapping("/queryProvinceList")
    public TableDataInfo queryProvinceList(AreaDTO areaDTO)
    {
        List<AreaDTO> list = achievementsService.queryProvinceList(areaDTO);

        return getDataTable(list);
    }

    @PostMapping("/queryCityList")
    public TableDataInfo queryCityList(AreaDTO areaDTO)
    {
        List<AreaDTO> list = achievementsService.queryCityList(areaDTO);

        return getDataTable(list);
    }

    @PostMapping("/queryWxuserList")
    public TableDataInfo queryWxuserList(WxuserinfoDTO wxuserinfoDTO)
    {
        List<WxuserinfoDTO> list = achievementsService.queryWxuserList(wxuserinfoDTO);

        return getDataTable(list);
    }

    @PostMapping("/updateWxuserLxflag")
    public AjaxResult updateWxuserLxflag(WxuserinfoDTO wxuserinfoDTO)
    {
        int i  = achievementsService.updateWxuserLxflag(wxuserinfoDTO);

        return toAjax(i);
    }


    /*
        查询积分订单
     */
    @PostMapping("/queryIntegralOrders")
    public TableDataInfo queryIntegralOrders(IntegralOrderDTO integralOrderDTO )

    {

        startPage();
        List<IntegralOrderDTO> list = achievementsService.queryIntegralOrders(integralOrderDTO);

        return getDataTable(list);
    }

    @PostMapping("/integralOrderFh")
    public AjaxResult integralOrderFh(IntegralOrderDTO integralOrderDTO )

    {
        int i = achievementsService.integralOrderFh(integralOrderDTO);

        return toAjax(i );
    }


}
